package com.wlr.study.leetcode;

/**
 * 两两交换链表中的节点
 * @author HustleLr
 * @version 1.0.0
 * @date 2024/1/22 18:40
 * @describe LeetCode24
 */
public class LeetCode24 {
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(0, head);
        ListNode curr = dummy;
        while(curr.next!=null&&curr.next.next!=null){
            ListNode last = curr.next.next;
            ListNode pre = curr.next;
            curr.next=last;
            pre.next=last.next;
            last.next=pre;
            curr=pre;
        }
        return dummy.next;
    }
}
